package homework_java.RoomQ.xy_java.src.Test;

import java.util.*;

public class Tools {
    Map<String, ArrayList<Student>> mStu =new HashMap<>();

    int x=0;
    void sort(StudentManager s){
        for(Student stu:s.stulist){
            if(x==0){
                ArrayList<Student> a=new ArrayList<>();
                a.add(stu);
                mStu.put(stu.smajor,a);
                x+=1;
            }

            else if(x!=0){
                boolean flag=true;
                Set<String> keys=mStu.keySet();
                for(String key:keys){
                    if(stu.smajor.equals(key)){
                        mStu.get(key).add(stu);
                        flag=false;
                        break;
                    }
                }
                if(flag){
                    ArrayList<Student> a=new ArrayList<>();
                    a.add(stu);
                    mStu.put(stu.smajor,a);
                }
            }
        }
       // System.out.println(mStu);
    }

    void show(){
        for (ArrayList<Student> list:mStu.values()) {
            Collections.sort(list, new Comparator<Student>() {
                public int compare(Student o1, Student o2) {
                    return o1.sno- o2.sno;
                }
            });
            for(Student student:list){

                System.out.println(student.toString());
            }
        }
    }




}
